/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import java.util.List;

import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.core.validate.QueryGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.query.IsfdCompositeMaterialQueryBo;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import com.comac.ins.isfd.domain.vo.IsfdCompositeMaterialVo;
import com.comac.ins.isfd.domain.bo.IsfdCompositeMaterialBo;
import com.comac.ins.isfd.service.IIsfdCompositeMaterialService;


/**
 * 【材料库复合材料】
 *
 * @author Lion Li
 * @date 2024-08-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/compositeMaterial")
public class IsfdCompositeMaterialController extends BaseController {

    private final IIsfdCompositeMaterialService isfdCompositeMaterialService;

    /**
     * 查询【材料库复合材料】列表
     */
    @SaCheckPermission("isfd:compositeMaterial:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdCompositeMaterialVo> list(@RequestBody IsfdCompositeMaterialQueryBo bo) {
        return isfdCompositeMaterialService.queryPageList(bo);
    }

    /**
     * 导出【材料库复合材料】列表
     */
    @SaCheckPermission("isfd:compositeMaterial:export")
    @Log(title = "【材料库复合材料】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdCompositeMaterialQueryBo bo, HttpServletResponse response) {
        List<IsfdCompositeMaterialVo> list = isfdCompositeMaterialService.queryList(bo);
        ExcelUtil.exportExcel(list, "【材料库复合材料】", IsfdCompositeMaterialVo.class, response);
    }

    /**
     * 获取【材料库复合材料】详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:compositeMaterial:query")
    @GetMapping("/{id}")
    public R<IsfdCompositeMaterialVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(isfdCompositeMaterialService.queryById(id));
    }

    /**
     * 新增【材料库复合材料】
     */
    @SaCheckPermission("isfd:compositeMaterial:add")
    @Log(title = "【材料库复合材料】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdCompositeMaterialBo bo) {
        return toAjax(isfdCompositeMaterialService.insertByBo(bo));
    }

    /**
     * 修改【材料库复合材料】
     */
    @SaCheckPermission("isfd:compositeMaterial:edit")
    @Log(title = "【材料库复合材料】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdCompositeMaterialBo bo) {
        return toAjax(isfdCompositeMaterialService.updateByBo(bo));
    }

    /**
     * 删除【材料库复合材料】
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:compositeMaterial:remove")
    @Log(title = "【材料库复合材料】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdCompositeMaterialService.deleteWithValidByIds(List.of(ids), true));
    }
}
